<template>
  <div class="risk">
    <eagle-page-list
      :controller="controller"
      :queryParams="queryParams"
      @bindData="bindData"
      :conditions="conditions"
      ref="eaglePageList"
    >
      <template #list>
        <eagle-cell
          style="margin-top: 10px"
          class="br-8"
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="warn_item">
          <div @click="goToDetail(item)">
            <div class="warn_header">
              <div>
                {{ index + 1 }}、{{ item.Name }}({{ item.NotifyCardCode }})
              </div>
            </div>
            <eagle-row gutter="20" class="dep_sort">
              <eagle-col span="24">
                <img
                  src="@/assets/Images/AppIcon/icon_list_user.png"
                  alt=""
                />{{ item.EditChnName }}
              </eagle-col>
              <eagle-col span="24">
                <img
                  src="@/assets/Images/AppIcon/icon_list_date.png"
                  alt=""
                />{{ item.EditDate }}
              </eagle-col>
            </eagle-row>
          </div>
          <eagle-divider class="line" />
          <div class="dep_btm">
            <div class="btm_item" @click="goToCheck(item)">
              <img src="@/assets/Images/AppIcon/icon_list_edit.png" alt="" />
              <div class="mr-10">措施复核</div>
            </div>
          </div>
          <div class="dep_btm">
            <div class="btm_item" @click="goFile(item.NotifyCardCode)">
              <img src="@/assets/Images/AppIcon/icon_list_check.png" alt="" />
              <div class="mr-10">查看卡片</div>
            </div>
          </div>
        </div>
        </eagle-cell>
      </template>
    </eagle-page-list>
  </div>
</template>

<script>
import { ImagePreview } from "vant";
import { mapGetters } from "vuex";
export default {
  computed: {
    ...mapGetters(["baseUrl", "CompanyCode"]),
  },
  data() {
    return {
      list: [],
      conditions: {},
      controller: "/RiskNotifyCard",
      queryParams: {
          dataType: "List",
      },
      tCode: "",
      isJG:false
    };
  },
  created() {
    this.isJG= this.$store.state.CompanyType=='JG'
  },
  methods: {
    bindData(data) {
      this.list = [];
      if (data) {
        this.list = data;
      }
    },
    goToDetail(item) {
      this.$router.push({
        path: "/RiskPoint/RiskNotifyCardDetail",
        query: { id: item.ID },
      });
    },
    goToCheck(item) {
      let _this = this;
      let params = {
        id: item.ID,
        CompanyCode: _this.CompanyCode,
      };
      _this.$axios
      .get("/RiskNotifyCard/GenerateToTemplate",{params:params})
      .then((res)=>{
        _this.form = res.data;
        _this.tCode = this.form.TCode;
        _this.goCheckList();
      })
    },
    goCheckList() {
      let url = this.isJG?"/Danger/DangerTemplateDetailJG":"/Danger/DangerTemplateDetail"
      this.$router.push({
        path: url,
        query: {
          tCode: this.tCode,
          CompanyCode: this.CompanyCode,
        },
      });
    },
    // 文件页面
    goFile(attachCode) {
      if (attachCode.startsWith("GZK")) {
        let _this = this;
        _this.$axios
        .get("/RiskNotifyCard/GetDetailByCode",{params:{code: attachCode}})
        .then((res) => {
          _this.preview(res.data.Attachs);
        });
      }
    },
    preview(item, index) {
      if (item) {
        let imgs = item.split(";");
        let arry = [];
        imgs.map((item, index) => {
          arry.push(this.baseUrl + item);
        });
        ImagePreview({
          images: arry,
          startPosition: index || 0,
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.all_dep {
  background-color: #ffffff;
}

.warn_item {
  background-color: #ffffff;
  /*margin-bottom: 10px;*/
  // padding: 10px 0 10px 10px;
  border-radius: 5px;
  position: relative;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: 0;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.dep_btm {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
  width: 30%;
  float: right;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
.line {
  margin: 5px 0;
}
</style>
